package view;
import java.awt.GridLayout;
import java.text.NumberFormat;

import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.BorderFactory;
import model.Model;
import model.Mp3Tags;
import java.awt.Color;
public class dataPane extends JPanel{ //Panel in dem sich die Textfelder und Label befinden
    	
//    public dataPane(Mp3Tags currentMp3) {
//        setLayout(new GridLayout(currentMp3.getNumberOfTags()/2, 2));
//        addGUIelements(currentMp3);
//    }
	private Model model = Model.getModel();
	private Mp3Tags currMp3 = model.getCurrentMp3();
	private dataTile[] datatiles = new dataTile[currMp3.getNumberOfTags()];
	private picTile pictile = new picTile();
	
	
    public dataPane() {
        int NumberOfRows =((datatiles.length % 2) == 0) ? (datatiles.length/2)+1 : (datatiles.length+1)/2;
        //                  Falls gerade Anzahl..   ..muss eine Zeile fuer das Bild hinzugefuegt werden.. ..ansonsten 
        
        setLayout(new GridLayout(NumberOfRows, 2));
        for(int i = 0; i < datatiles.length; i++){
            datatiles[i] = new dataTile(currMp3.getTagNameByIndex(i), i);
            add(datatiles[i]);
        }
        add(pictile);
        
        fillTiles();
        this.setBorder(BorderFactory.createLineBorder(Color.black));
        //addGUIelements(model.getCurrentMp3());
    }
    
    public void fillTiles(){
        for(int i = 0; i<datatiles.length; i++){
            datatiles[i].setText(model.getCurrentMp3().getValueByIndex(i));
        }
        pictile.setPicture(currMp3.getAlbumArt());
        
    }
    
    // erstellt je nach Tag-Typ ein entsprechendes GUI-Element
	/*private void addGUIelements(Mp3Tags m) {
		for(int i = 0; i < m.getNumberOfTags(); i++) {
			JLabel label = new JLabel();
			label.setText(m.getTagNameByIndex(i) + ":");
			
			switch(i)
			{
				case Mp3Tags.TAG_ALBUM: 
				case Mp3Tags.TAG_ARTIST:
				case Mp3Tags.TAG_TITLE:
					JTextField basic = new JTextField();
					basic.setText(m.getValueByIndex(i));
					this.add(basic);
					
					break;
					
				case Mp3Tags.TAG_YEAR:
					JTextField year = new JFormattedTextField(NumberFormat.getNumberInstance());
					year.setText(m.getValueByIndex(i));
					this.add(year);
					
					break;
			}
		}
	}*/
}
